<?php get_header(); ?>
<?php 	
	global $tax;
	global $product;

	$page = ((get_query_var("page") != '')? get_query_var("page") : 1);

	$agrs = array(

		'paged' => $page,
	    /* số bài post ở mỗi trang */
	    'showposts' => 12,

	    /* chỉ lấy post dạng product */
	    'post_type' => 'product',

	    'sort_by' => 'id'

	);

	$tax = new WP_query();

	$tax->query($agrs);

	// var_dump($tax);
	?>
	
	<?php
	woocommerce_product_subcategories();

?>
		
	<?php
	/**
	 * woocommerce_before_main_content hook
	 *
	 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
	 * @hooked woocommerce_breadcrumb - 20
	 */
	do_action('woocommerce_before_main_content');

	?>
		<?php if ( $tax->have_posts() ) : ?>

				<?php do_action('woocommerce_before_shop_loop'); ?>

				<ul class="products">

					<?php woocommerce_product_subcategories(); ?>
					<li id="top-product"></li>
					<?php while ( $tax->have_posts() ) : $tax->the_post(); ?>

						<?php woocommerce_get_template_part( 'content', 'product' ); ?>						

					<?php endwhile; // end of the loop. ?>

				</ul>

				<?php do_action('woocommerce_after_shop_loop'); ?>

			<?php else : ?>

				<?php if ( ! woocommerce_product_subcategories( array( 'before' => '<ul class="products">', 'after' => '</ul>' ) ) ) : ?>

					<p><?php _e( 'No products found which match your selection.', 'woocommerce' ); ?></p>

				<?php endif; ?>

			<?php endif; ?>

			<div class="clear"></div>

			<?php get_paging();?>	

		<?php
			/**
			 * woocommerce_after_main_content hook
			 *
			 * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
			 */
			do_action('woocommerce_after_main_content');
		?>
		<?php
		/**
		 * woocommerce_sidebar hook
		 *
		 * @hooked woocommerce_get_sidebar - 10
		 */
		do_action('woocommerce_sidebar');
		?>
<?php get_footer(); ?>